import request from '@/utils/request'

/**
 * 产品服务
 * @type {{loadAllProductNames: (function(): *), getProduct: (function(*=): *), addProduct: (function(*=): *), listProduct: (function(*): *), getProductImg: (function(*=): *), editShelf: (function(*=, *=): *), getProductTxt: (function(*=): *), deleteProduct: (function(*): *), getProductAttr: (function(*=): *), editProduct: (function(*=): *)}}
 */
export const ProductService = {
  // 产品名称列表-- 下拉框
  loadAllProductNames: function() { return request({ method: 'get', url: '/manage/product/all.do' }) },
  // 产品列表
  listProduct: function(query) { return request({ method: 'get', url: '/manage/product/list.do', params: { ...query }}) },
  // 产品规格列表
  listProductSku: function(productId) { return request({ method: 'get', url: '/manage/product/skus.do', params: { productId: productId }}) },
  // 产品详情
  getProduct: function(id) { return request({ method: 'get', url: '/manage/product/detail.do', params: { productId: id }}) },
  getProductTxt: function(id) { return request({ method: 'get', url: '/manage/product/txt/detail.do', params: { productId: id }}) },
  getProductImg: function(id) { return request({ method: 'get', url: '/manage/product/img/list.do', params: { productId: id }}) },
  getProductAttr: function(id) { return request({ method: 'get', url: '/manage/product/attr/list.do', params: { productId: id }}) },
  // 上架状态编辑
  editShelf: function(productId, isOnShelf) { return request({ method: 'get', url: '/manage/product/edit/shelf.do', params: { productId: productId, shelf: isOnShelf }}) },
  // 产品删除
  deleteProduct: function(id) { return request({ method: 'post', url: '/manage/product/delete.do', data: [id] }) },
  // 新增产品
  addProduct: function(data) { return request({ method: 'post', url: '/manage/product/add.do', data: data }) },
  // 编辑产品
  editProduct: function(data) { return request({ method: 'post', url: '/manage/product/edit.do', data: data }) },
  // 产品排序
  sortProduct: function(query) { return request({ method: 'get', url: '/manage/product/sort.do', params: { ...query }}) }
}

/**
 * 秒杀产品服务
 * @type {{enableProductSecKill: (function(*=, *=): *), addProductSecKill: (function(*=): *), deleteProductSecKill: (function(*): *), editProductSecKill: (function(*=): *), listProductSecKill: (function(*): *)}}
 */
export const ProductSecKillService = {
  // 秒杀产品列表
  listProductSecKill: function(query) { return request({ method: 'get', url: '/manage/product/seckill/list.do', params: { ...query }}) },
  // 状态编辑
  enableProductSecKill: function(secKillId, isEnable) { return request({ method: 'get', url: '/manage/product/seckill/enabled.do', params: { secKillId: secKillId, enable: isEnable }}) },
  // 秒杀产品删除
  deleteProductSecKill: function(id) { return request({ method: 'post', url: '/manage/product/seckill/delete.do', data: [id] }) },
  // 新增秒杀产品
  addProductSecKill: function(data) { return request({ method: 'post', url: '/manage/product/seckill/add.do', data: data }) },
  // 编辑秒杀产品
  editProductSecKill: function(data) { return request({ method: 'post', url: '/manage/product/seckill/edit.do', data: data }) }
}

/**
 * 运费模板服务
 * @type {{getAllFreightTemplateNames: (function(): *), addFreight: (function(*=): *), deleteFreight: (function(*): *), editFreight: (function(*=): *), listFreight: (function(*=): *), getFreight: (function(*=): *)}}
 */
export const FreightTemplateService = {
  // 所有的运费模板名称列表--下拉框选择
  getAllFreightTemplateNames: function() { return request({ method: 'get', url: '/manage/freight/all.do' }) },
  // 运费模板列表
  listFreight: function(params) { return request({ method: 'get', url: '/manage/freight/list.do', params: params }) },
  // 删除运费模板
  deleteFreight: function(id) { return request({ method: 'post', url: '/manage/freight/delete.do', data: [id] }) },
  // 添加运费模板
  addFreight: function(data) { return request({ method: 'post', url: '/manage/freight/add.do', data: data }) },
  // 运费模板详情
  getFreight: function(templateId) { return request({ method: 'get', url: '/manage/freight/detail.do', params: { templateId: templateId }}) },
  // 编辑运费模板
  editFreight: function(form) { return request({ method: 'post', url: '/manage/freight/edit.do', data: form }) }
}

/**
 * 产品类目服务
 * @type {{editCategory: (function(*=): *), loadCategoryTree: (function(): *), deleteCategory: (function(*): *), addCategory: (function(*=): *)}}
 */
export const CategoryService = {
  // 类目列表
  loadCategoryTree: function() { return request({ method: 'get', url: '/manage/category/all.do' }) },
  // 新增类目
  addCategory: function(data) { return request({ method: 'post', url: '/manage/category/add.do', data: data }) },
  // 编辑类目
  editCategory: function(data) { return request({ method: 'post', url: '/manage/category/edit.do', data: data }) },
  // 删除类目
  deleteCategory: function(id) { return request({ method: 'post', url: '/manage/category/delete.do', data: [id] }) }
}

